import Taro from '@tarojs/taro';

export const isDev = (): boolean => {
  return process.env.NODE_ENV === 'development';
};

export const isMobile = (): boolean => {
  const systemInfo = Taro.getSystemInfoSync();
  return systemInfo.platform === 'android' || systemInfo.platform === 'ios';
};

export const getCapsuleWidth = (): number => {
  if (Taro.getEnv() === Taro.ENV_TYPE.WEB) {
    return 64; // H5 环境直接返回 80
  }

  try {
    const menuButtonInfo = Taro.getMenuButtonBoundingClientRect();
    return menuButtonInfo.width || 80; // 如果获取到的宽度为 undefined，则返回 80
  } catch (error) {
    console.warn('getMenuButtonBoundingClientRect API not supported');
    return 64; // 如果 API 不支持，则返回 80
  }
};

export const getPaddingTop = (): number => {
  if (Taro.getEnv() === Taro.ENV_TYPE.WEB) {
    return 10; // H5 环境直接返回 10
  }

  try {
    const menuButtonInfo = Taro.getMenuButtonBoundingClientRect();
    return menuButtonInfo.top || 10; // 如果获取到的 top 为 undefined，则返回 10
  } catch (error) {
    console.warn('getMenuButtonBoundingClientRect API not supported');
    return 10; // 如果 API 不支持，则返回 10
  }
};
